/*
 * Copyright 2011 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.bezrabotnih.cabinet.client.ui;

import java.util.HashMap;
import java.util.List;

import net.bezrabotnih.cabinet.client.ui.ApplicantBlockView.Presenter;
import net.bezrabotnih.client.managed.request.JobProxy;
import net.bezrabotnih.client.managed.request.UserAccountProxy;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.place.shared.Place;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Sample implementation of {@link ApplicantsView}.
 */
public class ApplicantsViewImpl extends Composite implements ApplicantsView {

	interface Binder extends UiBinder<Widget, ApplicantsViewImpl> {
	}
	
	private static final Binder binder = GWT.create(Binder.class);
	@UiField VerticalPanel applicantsStackPanel;
	@UiField SimplePanel infoPanel;
	
	private HashMap<String,ApplicantBlockView> applicantBlockViews;

	private Presenter listener;
	

	public ApplicantsViewImpl() {
		initWidget(binder.createAndBindUi(this));
		applicantBlockViews=new HashMap<String, ApplicantBlockView>();
	}


	@Override
	public void setPresenter(Presenter listener) {
		this.listener = listener;
	}

	
	public void addApplicant(net.bezrabotnih.cabinet.client.ui.ApplicantBlockView.Presenter listener,String thumbnailUrl,String applicantId,String applicantName,String jobId,String jobName,boolean confirmed){
		
		ApplicantBlockView blockView=new ApplicantBlockView(listener, thumbnailUrl, applicantId, applicantName, jobId, jobName, confirmed);
		applicantBlockViews.put(applicantId+jobId,blockView);
		applicantsStackPanel.add(blockView);
	
		
	}
	
	public void clearApplicantsView(){
		if (applicantsStackPanel!=null) applicantsStackPanel.clear();
		if (applicantBlockViews!=null&&applicantBlockViews.size()>0) applicantBlockViews.clear();
		
	}


	@Override
	public void showFailureView(String blockKey) {
		ApplicantBlockView blockView=applicantBlockViews.get(blockKey);
		if (blockView!=null){
			blockView.confirmedFailureView();
			
		}
		
	}


	@Override
	public SimplePanel getInfoPanel() {
		
		return infoPanel;
	}


	@Override
	public void addApplicant(
			net.bezrabotnih.cabinet.client.ui.ApplicantBlockView.Presenter listener,
			UserAccountProxy applicant, JobProxy job, boolean confirmed) {
		ApplicantBlockView blockView=new ApplicantBlockView(listener, applicant,job, confirmed);
		applicantBlockViews.put(applicant.getId()+job.getId(),blockView);
		applicantsStackPanel.add(blockView);
		
	}


	
	
	
	
}
